<?php
    session_start();
    $name = $_POST['uname'];
    $upass = $_POST['upass'];
//    var_dump($_POST);
//    die;


//    var_dump($upass);

    $link = mysqli_connect("localhost","root","") or die("数据连接失败");
    mysqli_set_charset($link,"utf8");
    mysqli_select_db($link,"bbs");
    $sql = "select *  from user";
    $res = mysqli_query($link,$sql);
    if($res && mysqli_num_rows($res)>0) {
        $go = false;
        while ($rows = mysqli_fetch_assoc($res)) {
            if($rows['userName']==$name && $rows['password']==$upass && $rows['status']=='1') {
                $go = true;
                break;
//
            }
        }
        if($go){
            $_SESSION['id'] = $rows['id'];
            $_SESSION['name'] = $name;
            $_SESSION['upass'] = $upass;
//                var_dump($_SESSION['id']);
            echo "<script>alert('登录成功！');window.location.href='../index.php';</script>";

            die;
        }else{
            echo "<script>alert('登录失败！');window.location.href='../login.php';</script>";
            die;
        }
    }
    mysqli_close($link);